1 /***
2 * Redistribution and use of this software and associated documentation
3 * ("Software"), with or without modification, are permitted provided
4 * that the following conditions are met:
5 *
6 * 1. Redistributions of source code must retain copyright
7 * statements and notices. Redistributions must also contain a
8 * copy of this document.
9 *
10 * 2. Redistributions in binary form must reproduce the
11 * above copyright notice, this list of conditions and the
12 * following disclaimer in the documentation and/or other
13 * materials provided with the distribution.
14 *
15 * 3. The name "Exolab" must not be used to endorse or promote
16 * products derived from this Software without prior written
17 * permission of Exoffice Technologies. For written permission,
18 * please contact tma@netspace.net.au.
19 *
20 * 4. Products derived from this Software may not be called "Exolab"
21 * nor may "Exolab" appear in their names without prior written
22 * permission of Exoffice Technologies. Exolab is a registered
23 * trademark of Exoffice Technologies.
24 *
25 * 5. Due credit should be given to the Exolab Project
26 * (http://www.exolab.org/).
27 *
28 * THIS SOFTWARE IS PROVIDED BY EXOFFICE TECHNOLOGIES AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
30 * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
32 * EXOFFICE TECHNOLOGIES OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
33 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39 * OF THE POSSIBILITY OF SUCH DAMAGE.
40 *
41 * Copyright 2001-2004 (C) Exoffice Technologies Inc. All Rights Reserved.
42 *
43 * $Id: QueueMessageSender.java,v 1.3 2004/01/31 13:44:24 tanderson Exp $
44 */
45 package org.exolab.jmscts.core;
46
47 import javax.jms.JMSException;
48 import javax.jms.Message;
49 import javax.jms.QueueSender;
50
51 import org.apache.log4j.Category;
52
53
54 /***
55 * Class for sending messages using a {@link javax.jms.QueueSender}
56 *
57 * @version $Revision: 1.3 $ $Date: 2004/01/31 13:44:24 $
58 * @author <a href="mailto:tma@netspace.net.au">Tim Anderson</a>
59 * @see AbstractMessageSender
60 * @see TopicMessageSender
61 */
62 class QueueMessageSender extends AbstractMessageSender {
63
64 /***
65 * The logger
66 */
67 private static final Category log =
68 Category.getInstance(QueueMessageSender.class);
69
70
71 /***
72 * Construct an instance of with the sender to send messages with,
73 * using default values for delivery mode, priority, and time-to-live
74 *
75 * @param sender the topic sender to send messages with
76 */
77 public QueueMessageSender(QueueSender sender) {
78 super(sender, new MessagingBehaviour());
79 }
80
81 /***
82 * Construct an instance with the sender to send messages with,
83 * using values for delivery mode, priority, and time-to-live from the
84 * supplied messaging behaviour
85 *
86 * @param sender the sender to send messages with
87 * @param behaviour the messaging behaviour
88 */
89 public QueueMessageSender(QueueSender sender,
90 MessagingBehaviour behaviour) {
91 super(sender, behaviour);
92 }
93
94 /***
95 * Send messages to a destination, invoking a message populator prior
96 * to each message being sent
97 *
98 * @param message the message to send
99 * @param count the number of times to send the message
100 * @param populator the message populator, or null, if no population is
101 * required
102 * @param timeToLive the message time-to-live
103 * @throws JMSException if any of the JMS operations fail
104 */
105 public void send(Message message, int count, MessagePopulator populator,
106 long timeToLive)
107 throws JMSException {
108
109 MessagingBehaviour behaviour = getBehaviour();
110 int deliveryMode = behaviour.getDeliveryMode();
111 int priority = behaviour.getPriority();
112
113 QueueSender sender = (QueueSender) getProducer();
114 for (int i = 0; i < count; ++i) {
115 if (populator != null) {
116 try {
117 populator.populate(message);
118 } catch (Exception exception) {
119 JMSException error = new JMSException(
120 exception.getMessage());
121 error.setLinkedException(exception);
122 throw error;
123 }
124 }
125 if (log.isDebugEnabled()) {
126 Class type = MessageTypes.getType(message);
127 log.debug("Sending message " + "[message=" + type.getName()
128 + ", queue=" + getDestination()
129 + ", deliveryMode=" + deliveryMode
130 + ", priority=" + priority
131 + ", timeToLive=" + timeToLive + "]");
132 }
133 sender.send(message, deliveryMode, priority, timeToLive);
134 }
135 }
136
137 }
This page was automatically generated by Maven